home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / lib / partman / free_space / 50new / do_option < prev   
Encoding:
Text File  |  2009-04-19  |  5.5 KB  |  233 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. . /lib/partman/lib/base.sh
  6.  
  7. dev=$2
  8. freeid=$3
  9.  
  10. cd $dev
  11.  
  12. open_dialog PARTITION_INFO $freeid
  13. read_line x1 freeid freesize freetype x2 x3 x4
  14. close_dialog
  15.  
  16. [ "$freeid" ] || exit 1
  17.  
  18. freehsize=$(longint2human $freesize)
  19.  
  20. ask_for_size () {
  21.     local noninteractive
  22.     noninteractive=true
  23.     while true; do
  24.         size=''
  25.         while [ ! "$size" ]; do
  26.             db_set partman-partitioning/new_partition_size "$freehsize"
  27.             db_subst partman-partitioning/new_partition_size MAXSIZE "$freehsize"
  28.             db_input critical partman-partitioning/new_partition_size ||
  29.             $noninteractive
  30.             noninteractive="return 1"
  31.             db_go || return 1
  32.             db_get partman-partitioning/new_partition_size
  33.  
  34.             case "$RET" in
  35.                 max)
  36.                 size=$freesize
  37.                 hsize="$freehsize"
  38.                 ;;
  39.                 *%)
  40.                 digits=$(expr "$RET" : '\([1-9][0-9]*\) *%$')
  41.                 if [ "$digits" ]; then
  42.                     maxmb=$(convert_to_megabytes $freesize)
  43.                     size=$(($digits * $maxmb / 100))000000
  44.                 fi
  45.                 if [ "$digits" = 100 ]; then
  46.                     hsize="$freehsize"
  47.                 else
  48.                     hsize=some_number
  49.                 fi
  50.                 ;;
  51.                 *)
  52.                 if valid_human "$RET"; then
  53.                     size=$(human2longint "$RET")
  54.                 fi
  55.                 hsize="$RET"
  56.                 ;;
  57.             esac
  58.  
  59.             if [ -z "$size" ]; then
  60.                 db_input high partman-partitioning/bad_new_partition_size || true
  61.                 db_go || true
  62.             fi
  63.         done
  64.         if ask_for_type; then break; fi
  65.     done
  66.     return 0
  67. }
  68.  
  69. ask_for_type () {
  70.     local noninteractive has_primary parttype
  71.     has_primary=no
  72.     open_dialog PARTITIONS
  73.     while { read_line x1 x2 x3 parttype x5 x6 x7; [ "$parttype" ]; }; do
  74.         if [ "$parttype" = primary ]; then
  75.             has_primary=yes
  76.         fi
  77.     done
  78.     close_dialog
  79.  
  80.     noninteractive=true
  81.     while true; do
  82.         case "$freetype" in
  83.             primary)
  84.             $noninteractive
  85.             type=Primary
  86.             ;;
  87.             logical)
  88.             $noninteractive
  89.             type=Logical
  90.             ;;
  91.             pri/log)
  92.             if [ "$has_primary" = yes ]; then
  93.                 db_set partman-partitioning/new_partition_type Logical
  94.             else
  95.                 db_set partman-partitioning/new_partition_type Primary
  96.             fi
  97.             db_input critical partman-partitioning/new_partition_type ||
  98.                 $noninteractive
  99.             db_go || return 1
  100.             db_get partman-partitioning/new_partition_type
  101.             type="$RET"
  102.         esac
  103.         if ask_for_place; then break; fi
  104.         noninteractive="return 1"
  105.     done
  106. }
  107.  
  108. ask_for_place () {
  109.     local noninteractive
  110.     noninteractive=true
  111.     while true; do
  112.         if [ "$hsize" = "$freehsize" ]; then
  113.             $noninteractive
  114.             place=full
  115.         else
  116.             db_input critical partman-partitioning/new_partition_place ||
  117.                 $noninteractive
  118.             db_go || return 1
  119.             db_get partman-partitioning/new_partition_place
  120.             place="$RET"
  121.         fi
  122.         if create_new_partition; then break; fi
  123.         noninteractive="return 1"
  124.     done
  125. }
  126.  
  127. create_new_partition () {
  128.     # $type, $freeid, $place, and $size are global, passed down from
  129.     # elsewhere. TODO: these should really be function arguments.
  130.     open_dialog NEW_PARTITION $type ext2 $freeid $place $size
  131.     local num id fs mp mplist mpcurrent numparts device
  132.     id=''
  133.     read_line num id x1 x2 x3 x4 x5
  134.     close_dialog
  135.  
  136.     partitions=''
  137.     numparts=1
  138.     open_dialog PARTITIONS
  139.     while { read_line x1 part x3 x4 x5 x6 x7; [ "$part" ]; }; do
  140.         partitions="$partitions $part"
  141.         numparts=$(($numparts + 1))
  142.     done
  143.     close_dialog
  144.  
  145.     db_progress START 0 $numparts partman/text/please_wait
  146.     db_progress INFO partman-partitioning/new_state
  147.  
  148.     db_get partman/default_filesystem
  149.     default_fs="$RET"
  150.     if [ "$id" ] && [ -f "../../$default_fs" ]; then
  151.         # make better defaults for the new partition
  152.         mkdir -p $id
  153.         echo format >$id/method
  154.         >$id/format
  155.         >$id/use_filesystem
  156.         echo "$default_fs" >$id/filesystem
  157.         mkdir -p $id/options
  158.         if [ -f "/lib/partman/mountoptions/${default_fs}_defaults" ]; then
  159.             for op in $(cat "/lib/partman/mountoptions/${default_fs}_defaults"); do
  160.                 echo "$op" >"$id/options/$op"
  161.             done
  162.         fi
  163.         mplist='/ /home /usr /var /tmp /usr/local /opt /srv /boot'
  164.         mpcurrent=$(
  165.             for dev in $DEVICES/*; do
  166.                 [ -d $dev ] || continue
  167.                 cd $dev
  168.                 open_dialog PARTITIONS
  169.                 while { read_line num id x1 x2 fs x3 x4; [ "$id" ]; }; do
  170.                     [ $fs != free ] || continue
  171.                     [ -f "$id/method" ] || continue
  172.                     [ -f "$id/acting_filesystem" ] || continue
  173.                     [ -f "$id/use_filesystem" ] || continue
  174.                     [ -f "$id/mountpoint" ] || continue
  175.                     echo $(cat $id/mountpoint) # echo ensures 1 line
  176.                 done
  177.                 close_dialog
  178.             done
  179.         )
  180.         for mp in $mpcurrent; do
  181.             mplist=$(echo $mplist | sed "s,$mp,,")
  182.         done
  183.         mp=''
  184.         for mp in $mplist; do
  185.             break
  186.         done
  187.         if [ "$mp" ]; then
  188.             echo $mp >$id/mountpoint
  189.         fi
  190.         menudir_default_choice /lib/partman/active_partition "$default_fs" mountpoint || true
  191.         menudir_default_choice /lib/partman/choose_partition partition_tree $dev//$id || true
  192.         # setting the bootable flag is too much unnecessary work:
  193.         #   1. check if the disk label supports bootable flag
  194.         #   2. check if the mount point is / or /boot and the partition
  195.         #      type is `primary'
  196.         #   3. get the current flags
  197.         #   4. add `boot' and set the new flags
  198.         #   5. moreover, when the boot loader is installed in MBR
  199.         #      no bootable flag is necessary
  200.     fi
  201.  
  202.     db_progress STEP 1
  203.  
  204.     for part in $partitions; do
  205.         update_partition $dev $part
  206.         db_progress STEP 1
  207.     done
  208.  
  209.     db_progress STOP
  210.  
  211.     if [ "$id" ]; then
  212.         while true; do
  213.             set +e
  214.             device="$(humandev $(cat device))"
  215.             db_subst partman/active_partition DEVICE "$device"
  216.             db_subst partman/active_partition PARTITION "$num"
  217.             db_metaget partman/text/none_detected description
  218.             db_subst partman/active_partition OTHERINFO "${RET}"
  219.             ask_user /lib/partman/active_partition "$dev" "$id"
  220.             exitcode="$?"
  221.             if [ "$exitcode" -ge 128 ] && [ "$exitcode" -lt 192 ]; then
  222.                 exit "$exitcode" # killed by signal
  223.             elif [ "$exitcode" -ge 100 ]; then
  224.                 break
  225.             fi
  226.             set -e
  227.         done
  228.     fi
  229. }
  230.  
  231. ask_for_size || exit $?
  232. exit 0
  233.